let colorsIndex = 0
const colors = [
  '#FF8890',
  '#C1C2FF',
  '#7EDEFE',
  '#F8CCCC',
  '#D4EEBB',
  '#FEE774'
]

export const getColor = () => {
  return colors[colorsIndex++ % colors.length]
}

// 根究时间戳从小到大排序列表
export const sortListByTime = (list) => {
  return list
    .map((item) => {
      const createTime = (item.createTime || '').replace(/-/g, '/')
      return {
        ...item,
        color: getColor(),
        timestamp: +new Date(createTime)
      }
    })
    .sort((a, b) => a.timestamp - b.timestamp)
}

export const formatUsername = (username = '') => {
  if (username.length <= 1) {
    return '*'
  }
  return username[0] + '*'
}
